package com.example.demo.conf;

import io.lettuce.core.RedisClient;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import redis.clients.jedis.JedisPool;

import java.io.IOException;

@Configuration
public class BeanConfig {

    @Bean
    public JedisPool jedisPool() {
        return new JedisPool("192.168.3.27", 6382);
    }

    @Bean
    public RedisClient redisClient() {
        return RedisClient.create("redis://192.168.3.27:6382");
//        return RedisClient.create("192.168.3.27:6382");
    }

    @Bean
    public RedissonClient redissonClient() throws IOException {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://192.168.3.27:6382");
//        config.useSingleServer().setAddress("192.168.3.27:6382");
        return Redisson.create(config);
    }

    @Bean
    public Integer threadNum() {
        return 10;
    }

    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory factory){
        RedisTemplate redisTemplate = new RedisTemplate();
        RedisSerializer stringSerializer = new StringRedisSerializer();
        redisTemplate.setConnectionFactory(factory);
        redisTemplate.setKeySerializer(stringSerializer);
        redisTemplate.setValueSerializer(stringSerializer);
        redisTemplate.setHashKeySerializer(stringSerializer);
        redisTemplate.setHashValueSerializer(stringSerializer);
        return redisTemplate;
    }


}
